#include "typedef_stat.hpp"

#include <stdexcept>

#include "types.hpp"

TypedefStatement::TypedefStatement(std::string type, std::string name) {
    this->type = type;
    this->name = name;
}

std::string TypedefStatement::str() const {
    return "typedef " + this->type + ' ' + this->name;
}

void TypedefStatement::analyze() const {
    if (types.find(this->type) == types.end()) {
        throw std::runtime_error("Unknow type " + this->type);
    } else if (types.find(this->name) != types.end()) {
        throw std::runtime_error("Type " + this->name + " is alredy definded");
    }

    types.insert(std::pair<std::string, std::string>(this->name, types[this->type]));
}
